home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / POSIX.pm < prev    next >
Text File  |  1995-12-11  |  20KB  |  1,024 lines

  1. package POSIX;
  2.  
  3. use Carp;
  4. require Exporter;
  5. require AutoLoader;
  6. require DynaLoader;
  7. require Config;
  8. @ISA = (Exporter, AutoLoader, DynaLoader);
  9.  
  10. $H{assert_h} =    [qw(assert NDEBUG)];
  11.  
  12. $H{ctype_h} =    [qw(isalnum isalpha iscntrl isdigit isgraph islower
  13.         isprint ispunct isspace isupper isxdigit tolower toupper)];
  14.  
  15. $H{dirent_h} =    [qw()];
  16.  
  17. $H{errno_h} =   [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
  18.         EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
  19.         EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
  20.         ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
  21.         EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)];
  22.  
  23. $H{fcntl_h} =   [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
  24.         F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
  25.         O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
  26.         O_RDONLY O_RDWR O_TRUNC O_WRONLY
  27.         creat
  28.         SEEK_CUR SEEK_END SEEK_SET
  29.         S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  30.         S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
  31.         S_IWGRP S_IWOTH S_IWUSR)];
  32.  
  33. $H{float_h} =    [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
  34.         DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
  35.         DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
  36.         FLT_DIG FLT_EPSILON FLT_MANT_DIG
  37.         FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
  38.         FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
  39.         FLT_RADIX FLT_ROUNDS
  40.         LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
  41.         LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
  42.         LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)];
  43.  
  44. $H{grp_h} =    [qw()];
  45.  
  46. $H{limits_h} =    [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
  47.         INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
  48.         MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
  49.         PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
  50.         SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
  51.         ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
  52.         _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
  53.         _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
  54.         _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
  55.         _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)];
  56.  
  57. $H{locale_h} =  [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
  58.         LC_TIME NULL localeconv setlocale)];
  59.  
  60. $H{math_h} =    [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
  61.         frexp ldexp log10 modf pow sinh tanh)];
  62.  
  63. $H{pwd_h} =    [qw()];
  64.  
  65. $H{setjmp_h} =    [qw(longjmp setjmp siglongjmp sigsetjmp)];
  66.  
  67. $H{signal_h} =  [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
  68.         SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  69.         SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
  70.         SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
  71.         raise sigaction signal sigpending sigprocmask
  72.         sigsuspend)];
  73.  
  74. $H{stdarg_h} =    [qw()];
  75.  
  76. $H{stddef_h} =    [qw(NULL offsetof)];
  77.  
  78. $H{stdio_h} =   [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
  79.         L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET STREAM_MAX
  80.         TMP_MAX stderr stdin stdout _IOFBF _IOLBF _IONBF
  81.         clearerr fclose fdopen feof ferror fflush fgetc fgetpos
  82.         fgets fopen fprintf fputc fputs fread freopen
  83.         fscanf fseek fsetpos ftell fwrite getchar gets
  84.         perror putc putchar puts remove rewind
  85.         scanf setbuf setvbuf sscanf tmpfile tmpnam
  86.         ungetc vfprintf vprintf vsprintf)];
  87.  
  88. $H{stdlib_h} =  [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
  89.         abort atexit atof atoi atol bsearch calloc div
  90.         free getenv labs ldiv malloc mblen mbstowcs mbtowc
  91.         qsort realloc strtod strtol stroul wcstombs wctomb)];
  92.  
  93. $H{string_h} =  [qw(NULL memchr memcmp memcpy memmove memset strcat
  94.         strchr strcmp strcoll strcpy strcspn strerror strlen
  95.         strncat strncmp strncpy strpbrk strrchr strspn strstr
  96.         strtok strxfrm)];
  97.  
  98. $H{sys_stat_h} = [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  99.         S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
  100.         S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
  101.         fstat mkfifo)];
  102.  
  103. $H{sys_times_h} = [qw()];
  104.  
  105. $H{sys_types_h} = [qw()];
  106.  
  107. $H{sys_utsname_h} = [qw(uname)];
  108.  
  109. $H{sys_wait_h} = [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
  110.         WNOHANG WSTOPSIG WTERMSIG WUNTRACED)];
  111.  
  112. $H{termios_h} = [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
  113.         B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
  114.         CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
  115.         ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
  116.         INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
  117.         PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
  118.         TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
  119.         TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
  120.         VSTOP VSUSP VTIME
  121.         cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
  122.         tcflow tcflush tcgetattr tcsendbreak tcsetattr )];
  123.  
  124. $H{time_h} =    [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
  125.         difftime mktime strftime tzset tzname)];
  126.  
  127. $H{unistd_h} =  [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
  128.         STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
  129.         _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
  130.         _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
  131.         _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
  132.         _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
  133.         _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
  134.         _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
  135.         _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
  136.         _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
  137.         _exit access ctermid cuserid
  138.         dup2 dup execl execle execlp execv execve execvp
  139.         fpathconf getcwd getegid geteuid getgid getgroups
  140.         getpid getuid isatty lseek pathconf pause setgid setpgid
  141.         setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)];
  142.  
  143. $H{utime_h} =    [qw()];
  144.  
  145. sub expand {
  146.     local (@mylist);
  147.     foreach $entry (@_) {
  148.     if ($H{$entry}) {
  149.         push(@mylist, @{$H{$entry}});
  150.     }
  151.     else {
  152.         push(@mylist, $entry);
  153.     }
  154.     }
  155.     @mylist;
  156. }
  157.  
  158. @EXPORT = expand qw(assert_h ctype_h dirent_h errno_h fcntl_h float_h
  159.         grp_h limits_h locale_h math_h pwd_h setjmp_h signal_h
  160.         stdarg_h stddef_h stdio_h stdlib_h string_h sys_stat_h
  161.         sys_times_h sys_types_h sys_utsname_h sys_wait_h
  162.         termios_h time_h unistd_h utime_h);
  163.  
  164. @EXPORT_OK = qw(
  165.     closedir opendir readdir rewinddir
  166.     fcntl open
  167.     getgrgid getgrnam
  168.     atan2 cos exp log sin sqrt tan
  169.     getpwnam getpwuid
  170.     kill
  171.     fileno getc printf rename sprintf
  172.     abs exit rand srand system
  173.     chmod mkdir stat umask
  174.     times
  175.     wait waitpid
  176.     gmtime localtime time 
  177.     alarm chdir chown close fork getlogin getppid getpgrp link
  178.     pipe read rmdir sleep unlink write
  179.     utime
  180. );
  181.  
  182. sub import {
  183.     my $this = shift;
  184.     my @list = expand @_;
  185.     local $Exporter::ExportLevel = 1;
  186.     Exporter::import($this,@list);
  187. }
  188.  
  189. sub AUTOLOAD {
  190.     if ($AUTOLOAD =~ /::(_?[a-z])/) {
  191.     $AutoLoader::AUTOLOAD = $AUTOLOAD;
  192.     goto &AutoLoader::AUTOLOAD
  193.     }
  194.     local $constname = $AUTOLOAD;
  195.     $constname =~ s/.*:://;
  196.     $val = constant($constname, $_[0]);
  197.     if ($! != 0) {
  198.     if ($! =~ /Invalid/) {
  199.         croak "$constname is not a valid POSIX macro";
  200.     }
  201.     else {
  202.         croak "Your vendor has not defined POSIX macro $constname, used";
  203.     }
  204.     }
  205.     eval "sub $AUTOLOAD { $val }";
  206.     goto &$AUTOLOAD;
  207. }
  208.  
  209.  
  210. @liblist = ();
  211. @liblist = split ' ', $Config::Config{"POSIX_loadlibs"} 
  212.     if defined $Config::Config{"POSIX_loadlibs"};
  213. bootstrap POSIX @liblist;
  214.  
  215. sub usage { 
  216.     local ($mess) = @_;
  217.     croak "Usage: POSIX::$mess";
  218. }
  219.  
  220. sub redef { 
  221.     local ($mess) = @_;
  222.     croak "Use method $mess instead";
  223. }
  224.  
  225. sub unimpl { 
  226.     local ($mess) = @_;
  227.     $mess =~ s/xxx//;
  228.     croak "Unimplemented: POSIX::$mess";
  229. }
  230.  
  231. $gensym = "SYM000";
  232.  
  233. sub gensym {
  234.     *{"POSIX::" . $gensym++};
  235. }
  236.  
  237. sub ungensym {
  238.     local($x) = shift;
  239.     $x =~ s/.*:://;
  240.     delete $::_POSIX{$x};
  241. }
  242.  
  243. ############################
  244. package POSIX::SigAction;
  245.  
  246. sub new {
  247.     bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
  248. }
  249.  
  250. ############################
  251. package FileHandle;
  252.  
  253. sub new {
  254.     POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
  255.     local($class,$filename,$mode) = @_;
  256.     local($glob) = &POSIX::gensym;
  257.     $mode =~ s/a.*/>>/ ||
  258.     $mode =~ s/w.*/>/ ||
  259.     ($mode = '<');
  260.     open($glob, "$mode $filename");
  261.     bless \$glob;
  262. }
  263.  
  264. sub new_from_fd {
  265.     POSIX::usage "FileHandle->new_from_fd(fd,mode)" if @_ != 3;
  266.     local($class,$fd,$mode) = @_;
  267.     local($glob) = &POSIX::gensym;
  268.     $mode =~ s/a.*/>>/ ||
  269.     $mode =~ s/w.*/>/ ||
  270.     ($mode = '<');
  271.     open($glob, "$mode&=$fd");
  272.     bless \$glob;
  273. }
  274.  
  275. sub clearerr {
  276.     POSIX::usage "clearerr(filehandle)" if @_ != 1;
  277.     seek($_[0], 0, 1);
  278. }
  279.  
  280. sub close {
  281.     POSIX::usage "close(filehandle)" if @_ != 1;
  282.     close($_[0]);
  283.     ungensym($_[0]);
  284. }
  285.  
  286. sub eof {
  287.     POSIX::usage "eof(filehandle)" if @_ != 1;
  288.     eof($_[0]);
  289. }
  290.  
  291. sub getc {
  292.     POSIX::usage "getc(filehandle)" if @_ != 1;
  293.     getc($_[0]);
  294. }
  295.  
  296. sub gets {
  297.     POSIX::usage "gets(filehandle)" if @_ != 1;
  298.     local($handle) = @_;
  299.     scalar <$handle>;
  300. }
  301.  
  302. sub fileno {
  303.     POSIX::usage "fileno(filehandle)" if @_ != 1;
  304.     fileno($_[0]);
  305. }
  306.  
  307. sub seek {
  308.     POSIX::usage "seek(filehandle,pos,whence)" if @_ != 3;
  309.     seek($_[0], $_[1], $_[2]);
  310. }
  311.  
  312. sub tell {
  313.     POSIX::usage "tell(filehandle)" if @_ != 1;
  314.     tell($_[0]);
  315. }
  316. ############################
  317. package POSIX; # return to package POSIX so AutoSplit is happy
  318. 1;
  319. __END__
  320.  
  321. sub assert {
  322.     usage "assert(expr)" if @_ != 1;
  323.     if (!$_[0]) {
  324.     croak "Assertion failed";
  325.     }
  326. }
  327.  
  328. sub tolower {
  329.     usage "tolower(string)" if @_ != 1;
  330.     lc($_[0]);
  331. }
  332.  
  333. sub toupper {
  334.     usage "toupper(string)" if @_ != 1;
  335.     uc($_[0]);
  336. }
  337.  
  338. sub closedir {
  339.     usage "closedir(dirhandle)" if @_ != 1;
  340.     closedir($_[0]);
  341.     ungensym($_[0]);
  342. }
  343.  
  344. sub opendir {
  345.     usage "opendir(directory)" if @_ != 1;
  346.     local($dirhandle) = &gensym;
  347.     opendir($dirhandle, $_[0])
  348.     ? $dirhandle
  349.     : (ungensym($dirhandle), undef);
  350. }
  351.  
  352. sub readdir {
  353.     usage "readdir(dirhandle)" if @_ != 1;
  354.     readdir($_[0]);
  355. }
  356.  
  357. sub rewinddir {
  358.     usage "rewinddir(dirhandle)" if @_ != 1;
  359.     rewinddir($_[0]);
  360. }
  361.  
  362. sub errno {
  363.     usage "errno()" if @_ != 0;
  364.     $! + 0;
  365. }
  366.  
  367. sub creat {
  368.     usage "creat(filename, mode)" if @_ != 2;
  369.     &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[2]);
  370. }
  371.  
  372. sub fcntl {
  373.     usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
  374.     fcntl($_[0], $_[1], $_[2]);
  375. }
  376.  
  377. sub getgrgid {
  378.     usage "getgrgid(gid)" if @_ != 1;
  379.     getgrgid($_[0]);
  380. }
  381.  
  382. sub getgrnam {
  383.     usage "getgrnam(name)" if @_ != 1;
  384.     getgrnam($_[0]);
  385. }
  386.  
  387. sub atan2 {
  388.     usage "atan2(x,y)" if @_ != 2;
  389.     atan2($_[0], $_[1]);
  390. }
  391.  
  392. sub cos {
  393.     usage "cos(x)" if @_ != 1;
  394.     cos($_[0]);
  395. }
  396.  
  397. sub exp {
  398.     usage "exp(x)" if @_ != 1;
  399.     exp($_[0]);
  400. }
  401.  
  402. sub fabs {
  403.     usage "fabs(x)" if @_ != 1;
  404.     abs($_[0]);
  405. }
  406.  
  407. sub log {
  408.     usage "log(x)" if @_ != 1;
  409.     log($_[0]);
  410. }
  411.  
  412. sub pow {
  413.     usage "pow(x,exponent)" if @_ != 2;
  414.     $_[0] ** $_[1];
  415. }
  416.  
  417. sub sin {
  418.     usage "sin(x)" if @_ != 1;
  419.     sin($_[0]);
  420. }
  421.  
  422. sub sqrt {
  423.     usage "sqrt(x)" if @_ != 1;
  424.     sqrt($_[0]);
  425. }
  426.  
  427. sub tan {
  428.     usage "tan(x)" if @_ != 1;
  429.     tan($_[0]);
  430. }
  431.  
  432. sub getpwnam {
  433.     usage "getpwnam(name)" if @_ != 1;
  434.     getpwnam($_[0]);
  435. }
  436.  
  437. sub getpwuid {
  438.     usage "getpwuid(uid)" if @_ != 1;
  439.     getpwuid($_[0]);
  440. }
  441.  
  442. sub longjmp {
  443.     unimpl "longjmp() is C-specific: use die instead";
  444. }
  445.  
  446. sub setjmp {
  447.     unimpl "setjmp() is C-specific: use eval {} instead";
  448. }
  449.  
  450. sub siglongjmp {
  451.     unimpl "siglongjmp() is C-specific: use die instead";
  452. }
  453.  
  454. sub sigsetjmp {
  455.     unimpl "sigsetjmp() is C-specific: use eval {} instead";
  456. }
  457.  
  458. sub kill {
  459.     usage "kill(pid, sig)" if @_ != 2;
  460.     kill $_[1], $_[0];
  461. }
  462.  
  463. sub raise {
  464.     usage "raise(sig)" if @_ != 1;
  465.     kill $$, $_[0];    # Is this good enough?
  466. }
  467.  
  468. sub offsetof {
  469.     unimpl "offsetof() is C-specific, stopped";
  470. }
  471.  
  472. sub clearerr {
  473.     redef "$filehandle->clearerr(filehandle)";
  474. }
  475.  
  476. sub fclose {
  477.     redef "$filehandle->fclose(filehandle)";
  478. }
  479.  
  480. sub fdopen {
  481.     redef "FileHandle->new_from_fd(fd,mode)";
  482. }
  483.  
  484. sub feof {
  485.     redef "$filehandle->eof()";
  486. }
  487.  
  488. sub fgetc {
  489.     redef "$filehandle->getc()";
  490. }
  491.  
  492. sub fgets {
  493.     redef "$filehandle->gets()";
  494. }
  495.  
  496. sub fileno {
  497.     redef "$filehandle->fileno()";
  498. }
  499.  
  500. sub fopen {
  501.     redef "FileHandle->open()";
  502. }
  503.  
  504. sub fprintf {
  505.     unimpl "fprintf() is C-specific--use printf instead";
  506. }
  507.  
  508. sub fputc {
  509.     unimpl "fputc() is C-specific--use print instead";
  510. }
  511.  
  512. sub fputs {
  513.     unimpl "fputs() is C-specific--use print instead";
  514. }
  515.  
  516. sub fread {
  517.     unimpl "fread() is C-specific--use read instead";
  518. }
  519.  
  520. sub freopen {
  521.     unimpl "freopen() is C-specific--use open instead";
  522. }
  523.  
  524. sub fscanf {
  525.     unimpl "fscanf() is C-specific--use <> and regular expressions instead";
  526. }
  527.  
  528. sub fseek {
  529.     redef "$filehandle->seek(pos,whence)";
  530. }
  531.  
  532. sub ferror {
  533.     redef "$filehandle->error()";
  534. }
  535.  
  536. sub fflush {
  537.     redef "$filehandle->flush()";
  538. }
  539.  
  540. sub fgetpos {
  541.     redef "$filehandle->getpos()";
  542. }
  543.  
  544. sub fsetpos {
  545.     redef "$filehandle->setpos(pos)";
  546. }
  547.  
  548. sub ftell {
  549.     redef "$filehandle->tell()";
  550. }
  551.  
  552. sub fwrite {
  553.     unimpl "fwrite() is C-specific--use print instead";
  554. }
  555.  
  556. sub getc {
  557.     usage "getc(handle)" if @_ != 1;
  558.     getc($_[0]);
  559. }
  560.  
  561. sub getchar {
  562.     usage "getchar()" if @_ != 0;
  563.     getc(STDIN);
  564. }
  565.  
  566. sub gets {
  567.     usage "gets()" if @_ != 0;
  568.     scalar <STDIN>;
  569. }
  570.  
  571. sub perror {
  572.     print STDERR "@_: " if @_;
  573.     print STDERR $!,"\n";
  574. }
  575.  
  576. sub printf {
  577.     usage "printf(pattern, args...)" if @_ < 1;
  578.     printf STDOUT @_;
  579. }
  580.  
  581. sub putc {
  582.     unimpl "putc() is C-specific--use print instead";
  583. }
  584.  
  585. sub putchar {
  586.     unimpl "putchar() is C-specific--use print instead";
  587. }
  588.  
  589. sub puts {
  590.     unimpl "puts() is C-specific--use print instead";
  591. }
  592.  
  593. sub remove {
  594.     usage "remove(filename)" if @_ != 1;
  595.     unlink($_[0]);
  596. }
  597.  
  598. sub rename {
  599.     usage "rename(oldfilename, newfilename)" if @_ != 2;
  600.     rename($_[0], $_[1]);
  601. }
  602.  
  603. sub rewind {
  604.     usage "rewind(filehandle)" if @_ != 1;
  605.     seek($_[0],0,0);
  606. }
  607.  
  608. sub scanf {
  609.     unimpl "scanf() is C-specific--use <> and regular expressions instead";
  610. }
  611.  
  612. sub sprintf {
  613.     usage "sprintf(pattern,args)" if @_ == 0;
  614.     sprintf(shift,@_);
  615. }
  616.  
  617. sub sscanf {
  618.     unimpl "sscanf() is C-specific--use regular expressions instead";
  619. }
  620.  
  621. sub tmpfile {
  622.     redef "FileHandle->new_tmpfile()";
  623. }
  624.  
  625. sub ungetc {
  626.     redef "$filehandle->ungetc(char)";
  627. }
  628.  
  629. sub vfprintf {
  630.     unimpl "vfprintf() is C-specific";
  631. }
  632.  
  633. sub vprintf {
  634.     unimpl "vprintf() is C-specific";
  635. }
  636.  
  637. sub vsprintf {
  638.     unimpl "vsprintf() is C-specific";
  639. }
  640.  
  641. sub abs {
  642.     usage "abs(x)" if @_ != 1;
  643.     abs($_[0]);
  644. }
  645.  
  646. sub atexit {
  647.     unimpl "atexit() is C-specific: use END {} instead";
  648. }
  649.  
  650. sub atof {
  651.     unimpl "atof() is C-specific, stopped";
  652. }
  653.  
  654. sub atoi {
  655.     unimpl "atoi() is C-specific, stopped";
  656. }
  657.  
  658. sub atol {
  659.     unimpl "atol() is C-specific, stopped";
  660. }
  661.  
  662. sub bsearch {
  663.     unimpl "bsearch(xxx)" if @_ != 123;
  664.     bsearch($_[0]);
  665. }
  666.  
  667. sub calloc {
  668.     unimpl "calloc() is C-specific, stopped";
  669. }
  670.  
  671. sub div {
  672.     unimpl "div() is C-specific, stopped";
  673. }
  674.  
  675. sub exit {
  676.     usage "exit(status)" if @_ != 1;
  677.     exit($_[0]);
  678. }
  679.  
  680. sub free {
  681.     unimpl "free() is C-specific, stopped";
  682.     free($_[0]);
  683. }
  684.  
  685. sub getenv {
  686.     usage "getenv(name)" if @_ != 1;
  687.     $ENV{$_[0]};
  688. }
  689.  
  690. sub labs {
  691.     unimpl "labs() is C-specific, use abs instead";
  692. }
  693.  
  694. sub ldiv {
  695.     unimpl "ldiv() is C-specific, use / and int instead";
  696. }
  697.  
  698. sub malloc {
  699.     unimpl "malloc() is C-specific, stopped";
  700. }
  701.  
  702. sub qsort {
  703.     unimpl "qsort() is C-specific, use sort instead";
  704. }
  705.  
  706. sub rand {
  707.     unimpl "rand() is non-portable, use Perl's rand instead";
  708. }
  709.  
  710. sub realloc {
  711.     unimpl "realloc() is C-specific, stopped";
  712. }
  713.  
  714. sub srand {
  715.     unimpl "srand()";
  716. }
  717.  
  718. sub strtod {
  719.     unimpl "strtod() is C-specific, stopped";
  720. }
  721.  
  722. sub strtol {
  723.     unimpl "strtol() is C-specific, stopped";
  724. }
  725.  
  726. sub stroul {
  727.     unimpl "stroul() is C-specific, stopped";
  728. }
  729.  
  730. sub system {
  731.     usage "system(command)" if @_ != 1;
  732.     system($_[0]);
  733. }
  734.  
  735. sub memchr {
  736.     unimpl "memchr() is C-specific, use index() instead";
  737. }
  738.  
  739. sub memcmp {
  740.     unimpl "memcmp() is C-specific, use eq instead";
  741. }
  742.  
  743. sub memcpy {
  744.     unimpl "memcpy() is C-specific, use = instead";
  745.     memcpy($_[0]);
  746.  
  747. sub memmove {
  748.     unimpl "memmove() is C-specific, use = instead";
  749. }
  750.  
  751. sub memset {
  752.     unimpl "memset() is C-specific, use x instead";
  753. }
  754.  
  755. sub strcat {
  756.     unimpl "strcat() is C-specific, use .= instead";
  757. }
  758.  
  759. sub strchr {
  760.     unimpl "strchr() is C-specific, use index() instead";
  761. }
  762.  
  763. sub strcmp {
  764.     unimpl "strcmp() is C-specific, use eq instead";
  765. }
  766.  
  767. sub strcpy {
  768.     unimpl "strcpy() is C-specific, use = instead";
  769. }
  770.  
  771. sub strcspn {
  772.     unimpl "strcspn() is C-specific, use regular expressions instead";
  773. }
  774.  
  775. sub strerror {
  776.     usage "strerror(errno)" if @_ != 1;
  777.     local $! = $_[0];
  778.     $! . "";
  779. }
  780.  
  781. sub strlen {
  782.     unimpl "strlen() is C-specific, use length instead";
  783. }
  784.  
  785. sub strncat {
  786.     unimpl "strncat() is C-specific, use .= instead";
  787. }
  788.  
  789. sub strncmp {
  790.     unimpl "strncmp() is C-specific, use eq instead";
  791. }
  792.  
  793. sub strncpy {
  794.     unimpl "strncpy() is C-specific, use = instead";
  795. }
  796.  
  797. sub strpbrk {
  798.     unimpl "strpbrk() is C-specific, stopped";
  799. }
  800.  
  801. sub strrchr {
  802.     unimpl "strrchr() is C-specific, use rindex() instead";
  803. }
  804.  
  805. sub strspn {
  806.     unimpl "strspn() is C-specific, stopped";
  807. }
  808.  
  809. sub strstr {
  810.     usage "strstr(big, little)" if @_ != 2;
  811.     index($_[0], $_[1]);
  812. }
  813.  
  814. sub strtok {
  815.     unimpl "strtok() is C-specific, stopped";
  816. }
  817.  
  818. sub chmod {
  819.     usage "chmod(filename, mode)" if @_ != 2;
  820.     chmod($_[0], $_[1]);
  821. }
  822.  
  823. sub fstat {
  824.     usage "fstat(fd)" if @_ != 1;
  825.     local(*TMP);
  826.     open(TMP, "<&$_[0]");        # Gross.
  827.     local(@l) = stat(TMP);
  828.     close(TMP);
  829.     @l;
  830. }
  831.  
  832. sub mkdir {
  833.     usage "mkdir(directoryname, mode)" if @_ != 2;
  834.     mkdir($_[0], $_[1]);
  835. }
  836.  
  837. sub stat {
  838.     usage "stat(filename)" if @_ != 1;
  839.     stat($_[0]);
  840. }
  841.  
  842. sub umask {
  843.     usage "umask(mask)" if @_ != 1;
  844.     umask($_[0]);
  845. }
  846.  
  847. sub times {
  848.     usage "times()" if @_ != 0;
  849.     times();
  850. }
  851.  
  852. sub wait {
  853.     usage "wait(statusvariable)" if @_ != 1;
  854.     local $result = wait();
  855.     $_[0] = $?;
  856.     $result;
  857. }
  858.  
  859. sub waitpid {
  860.     usage "waitpid(pid, statusvariable, options)" if @_ != 3;
  861.     local $result = waitpid($_[0], $_[2]);
  862.     $_[1] = $?;
  863.     $result;
  864. }
  865.  
  866. sub gmtime {
  867.     usage "gmtime(time)" if @_ != 1;
  868.     gmtime($_[0]);
  869. }
  870.  
  871. sub localtime {
  872.     usage "localtime(time)" if @_ != 1;
  873.     localtime($_[0]);
  874. }
  875.  
  876. sub time {
  877.     unimpl "time()" if @_ != 0;
  878.     time;
  879. }
  880.  
  881. sub alarm {
  882.     usage "alarm(seconds)" if @_ != 1;
  883.     alarm($_[0]);
  884. }
  885.  
  886. sub chdir {
  887.     usage "chdir(directory)" if @_ != 1;
  888.     chdir($_[0]);
  889. }
  890.  
  891. sub chown {
  892.     usage "chown(filename, uid, gid)" if @_ != 3;
  893.     chown($_[0], $_[1], $_[2]);
  894. }
  895.  
  896. sub execl {
  897.     unimpl "execl() is C-specific, stopped";
  898.     execl($_[0]);
  899. }
  900.  
  901. sub execle {
  902.     unimpl "execle() is C-specific, stopped";
  903.     execle($_[0]);
  904. }
  905.  
  906. sub execlp {
  907.     unimpl "execlp() is C-specific, stopped";
  908.     execlp($_[0]);
  909. }
  910.  
  911. sub execv {
  912.     unimpl "execv() is C-specific, stopped";
  913.     execv($_[0]);
  914. }
  915.  
  916. sub execve {
  917.     unimpl "execve() is C-specific, stopped";
  918.     execve($_[0]);
  919. }
  920.  
  921. sub execvp {
  922.     unimpl "execvp() is C-specific, stopped";
  923.     execvp($_[0]);
  924. }
  925.  
  926. sub fork {
  927.     usage "fork()" if @_ != 0;
  928.     fork;
  929. }
  930.  
  931. sub getcwd
  932. {
  933.     usage "getcwd()" if @_ != 0;
  934.     chop($cwd = `pwd`);
  935.     $cwd;
  936. }
  937.  
  938. sub getegid {
  939.     usage "getegid()" if @_ != 0;
  940.     $) + 0;
  941. }
  942.  
  943. sub geteuid {
  944.     usage "geteuid()" if @_ != 0;
  945.     $> + 0;
  946. }
  947.  
  948. sub getgid {
  949.     usage "getgid()" if @_ != 0;
  950.     $( + 0;
  951. }
  952.  
  953. sub getgroups {
  954.     usage "getgroups()" if @_ != 0;
  955.     local(%seen) = ();
  956.     grep(!$seen{$_}++, split(' ', $) ));
  957. }
  958.  
  959. sub getlogin {
  960.     usage "getlogin()" if @_ != 0;
  961.     getlogin();
  962. }
  963.  
  964. sub getpgrp {
  965.     usage "getpgrp()" if @_ != 0;
  966.     getpgrp($_[0]);
  967. }
  968.  
  969. sub getpid {
  970.     usage "getpid()" if @_ != 0;
  971.     $$;
  972. }
  973.  
  974. sub getppid {
  975.     usage "getppid()" if @_ != 0;
  976.     getppid;
  977. }
  978.  
  979. sub getuid {
  980.     usage "getuid()" if @_ != 0;
  981.     $<;
  982. }
  983.  
  984. sub isatty {
  985.     usage "isatty(filehandle)" if @_ != 1;
  986.     -t $_[0];
  987. }
  988.  
  989. sub link {
  990.     usage "link(oldfilename, newfilename)" if @_ != 2;
  991.     link($_[0], $_[1]);
  992. }
  993.  
  994. sub rmdir {
  995.     usage "rmdir(directoryname)" if @_ != 1;
  996.     rmdir($_[0]);
  997. }
  998.  
  999. sub setgid {
  1000.     usage "setgid(gid)" if @_ != 1;
  1001.     $( = $_[0];
  1002. }
  1003.  
  1004. sub setuid {
  1005.     usage "setuid(uid)" if @_ != 1;
  1006.     $< = $_[0];
  1007. }
  1008.  
  1009. sub sleep {
  1010.     usage "sleep(seconds)" if @_ != 1;
  1011.     sleep($_[0]);
  1012. }
  1013.  
  1014. sub unlink {
  1015.     usage "unlink(filename)" if @_ != 1;
  1016.     unlink($_[0]);
  1017. }
  1018.  
  1019. sub utime {
  1020.     usage "utime(filename, atime, mtime)" if @_ != 3;
  1021.     utime($_[1], $_[2], $_[0]);
  1022. }
  1023.  
  1024.